<div style="width:240px;margin:50px auto;" id="menulist">

    <div class="menuDiv">
        <h3>网站记录</h3>
        <ul>
            <li><a href="/fangke">最近登录用户</a></li>
            <li><a href="/xinqingriji">我的心情日记</a></li>
            <li><a href="/gerenziliao">我的个人资料</a></li>
            <li><a href="javascript:void(0);">广告代码</a></li>
            <li><a href="javascript:void(0);">QQ客服</a></li>
        </ul>
    </div>

    <div class="menuDiv">
        <h3>欣赏借鉴</h3>
        <ul>
            <li><a href="javascript:void(0);">企业类网站</a></li>
            <li><a href="javascript:void(0);">行业类网站</a></li>
            <li><a href="javascript:void(0);">BLOG类网站</a></li>
            <li><a href="javascript:void(0);">门户类网站</a></li>
            <li><a href="javascript:void(0);">商城类网站</a></li>
        </ul>
    </div>

    <div class="menuDiv">
        <h3>建站技巧</h3>
        <ul>
            <li><a href="javascript:void(0);">企业类网站</a></li>
            <li><a href="javascript:void(0);">行业类网站</a></li>
            <li><a href="javascript:void(0);">BLOG类网站</a></li>
            <li><a href="javascript:void(0);">门户类网站</a></li>
            <li><a href="javascript:void(0);">商城类网站</a></li>
            <li><a href="javascript:void(0);">企业类网站</a></li>
            <li><a href="javascript:void(0);">行业类网站</a></li>
            <li><a href="javascript:void(0);">BLOG类网站</a></li>
            <li><a href="javascript:void(0);">门户类网站</a></li>
            <li><a href="javascript:void(0);">商城类网站</a></li>
        </ul>
    </div>

    <div class="menuDiv">
        <h3>YY频道设计</h3>
        <ul>
            <li><a href="javascript:void(0);">yy娱乐频道设计</a></li>
            <li><a href="javascript:void(0);">yy情侣频道设计图</a></li>
            <li><a href="javascript:void(0);">yy游戏频道设计图</a></li>
            <li><a href="javascript:void(0);">YY个性签名</a></li>
        </ul>
    </div>

</div>

<script type="text/javascript">
    function MenuSwitch(className){
        this._elements = [];
        this._default = -1;
        this._className = className;
        this._previous = false;
    }
    MenuSwitch.prototype.setDefault = function(id){
        this._default = Number(id);
    }
    MenuSwitch.prototype.setPrevious = function(flag){
        this._previous = Boolean(flag);
    }
    MenuSwitch.prototype.collectElementbyClass = function(){
        this._elements = [];
        var allelements = document.getElementsByTagName("div");
        for(var i=0;i<allelements.length;i++){
            var mItem = allelements[i];
            if (typeof mItem.className == "string" && mItem.className == this._className){
                var h3s = mItem.getElementsByTagName("h3");
                var uls = mItem.getElementsByTagName("ul");
                if(h3s.length == 1 && uls.length == 1){
                    h3s[0].style.cursor = "hand";
                    if(this._default == this._elements.length){
                        uls[0].style.display = "block";
                    }else{
                        uls[0].style.display = "none";
                    }
                    this._elements[this._elements.length] = mItem;
                }
            }
        }
    }
    MenuSwitch.prototype.open = function(mElement){
        var uls = mElement.getElementsByTagName("ul");
        uls[0].style.display = "block";
    }
    MenuSwitch.prototype.close = function(mElement){
        var uls = mElement.getElementsByTagName("ul");
        uls[0].style.display = "none";
    }
    MenuSwitch.prototype.isOpen = function(mElement){
        var uls = mElement.getElementsByTagName("ul");
        return uls[0].style.display == "block";
    }
    MenuSwitch.prototype.toggledisplay = function(header){
        var mItem;
        if(window.addEventListener){
            mItem = header.parentNode;
        }else{
            mItem = header.parentElement;
        }
        if(this.isOpen(mItem)){
            this.close(mItem);
        }else{
            this.open(mItem);
        }
        if(!this._previous){
            for(var i=0;i<this._elements.length;i++){
                if(this._elements[i] != mItem){
                    var uls = this._elements[i].getElementsByTagName("ul");
                    uls[0].style.display = "none";
                }
            }
        }
    }
    MenuSwitch.prototype.init = function(){
        var instance = this;
        this.collectElementbyClass();
        if(this._elements.length==0){
            return;
        }
        for(var i=0;i<this._elements.length;i++){
            var h3s = this._elements[i].getElementsByTagName("h3");
            if(window.addEventListener){
                h3s[0].addEventListener("click",function(){instance.toggledisplay(this);},false);
            }else{
                h3s[0].onclick = function(){instance.toggledisplay(this);}
            }
        }
    }
</script>



<script language="javascript">
    var mSwitch = new MenuSwitch("menuDiv");
    mSwitch.setDefault(0);
    mSwitch.setPrevious(false);
    mSwitch.init();
</script>